package com.zhu.library_management_system.repository;

import com.zhu.library_management_system.pojo.Book;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BookRepository extends PagingAndSortingRepository<Book,Integer> {
    Book findByTitle(String title);

    @Modifying
    @Query("UPDATE Book b SET b.stock = ?2 WHERE b.id = ?1")
    void stock(Integer id, Integer stock);

    @Query("SELECT b.stock FROM Book b WHERE b.id = ?1")
    Integer findStock(Integer id);

    @Query("SELECT b.bookStatus FROM Book b WHERE b.id = ?1")
    String getBookStatus(Integer id);

    @Modifying
    @Query("UPDATE Book b SET b.bookStatus = ?2 WHERE b.id = ?1")
    void updateBookStatus(Integer id, String bookStatus);
}
